﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class NPS_app_MasterData_ReasonCategory : PageBase
{
    #region Events
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (getMode == FormMode.Editor)
            {
                loadData();
                btnSave.Text = "Update";
                lblHeader.Text = "Master Data: Reason Category Edit";
            }
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        Entities.NPSReasonCategory ReasonCategory = new Entities.NPSReasonCategory()
        {
            sxTitle = setStringSecurity(txtTitle.Text),
            sxDetail = setStringSecurity(txtDetail.Text)
        };
        if (getMode == FormMode.Editor)
        {
            ReasonCategory.sxUpdater = ICPUser.ID;
            ReasonCategory.iID = getItemID;
            updateReasonCategory(ReasonCategory);
        }
        else { saveReasonCategory(ReasonCategory); }
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {

    }

    #endregion

    #region Audy's Custom Function
    protected void loadData()
    {
        //fetch data from DB
        Controller.NPSReasonCategoryController ATController = new Controller.NPSReasonCategoryController();
        Entities.NPSReasonCategory ReasonCategory = ATController.getNPSReasonCategory(getItemID);

        //set all data to forms
        txtTitle.Text = ReasonCategory.sxTitle;
        txtDetail.Text = ReasonCategory.sxDetail;
    }

    protected bool saveReasonCategory(Entities.NPSReasonCategory ReasonCategory)
    {
        Controller.NPSReasonCategoryController SRCController = new Controller.NPSReasonCategoryController();
        if (SRCController.InsertNPSReasonCategoryData(ReasonCategory) == 0)
        { return false; }
        else { return true; }
    }

    protected void updateReasonCategory(Entities.NPSReasonCategory ReasonCategory)
    {
        Controller.NPSReasonCategoryController ANController = new Controller.NPSReasonCategoryController();
        ANController.UpdateNPSReasonCategoryData(ReasonCategory);
    }
    #endregion
}
